package test_keskkond;

import java.sql.ResultSet;
import java.sql.SQLException;

import database.DBConnection;

import model.subjects.Subject;

public class TestQuery {
	DBConnection db = new DBConnection();
	public ResultSet getSubjectsByName(String name){
		String sql = "SELECT P.subject_id ,P.subject_name, P.subject_type FROM "
				+"(SELECT person AS subject_id, 'isik'  AS subject_type, last_name AS subject_name FROM person WHERE UPPER(last_name) LIKE UPPER('%"+name+"%') "
				+"UNION SELECT enterprise AS subject_id, 'ettevote'  AS subject_type, name AS subject_name FROM enterprise WHERE UPPER(name) LIKE UPPER('%"+name+"%' )) AS P;";
		
		try {
			return db.executeQuery(sql);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		
	
	}
}
